import Vue from 'vue'
import VueRouter from 'vue-router'
// 导入登录注册页面组件
import Reg from "@/view/Reg/Reg.vue"
import Login from "@/view/Login/Login.vue"
import Main from "@/view/Main/Main.vue"
import Home from '@/view/Menus/Home/Home.vue'
import UserInfo from '@/view/Menus/User/UserInfo.vue'
import UserAvatar from '@/view/Menus/User/UserAvatar.vue'
import UserPwd from '@/view/Menus/User/UserPwd.vue'
import ArtCate from '@/view/Menus/Article/ArtCate.vue'
import ArtList from '@/view/Menus/Article/ArtList.vue'

Vue.use(VueRouter)

// 防止路由报错的问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

// 声明路由规则
const routes = [
  { path: '/reg', name: 'reg', component: Reg },
  { path: '/login', name: 'login', component: Login },
  {
    path: '/',
    name: 'main',
    component: Main,
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'home',
        component: Home
      },
      // 用户信息
      {
        path: 'user-info',
        name: 'userInfo',
        component: UserInfo
      },
      // 用户头像
      {
        path: 'user-avatar',
        name: 'userAvatar',
        component: UserAvatar
      },
      // 用户密码
      {
        path: 'user-pwd',
        name: 'userPwd',
        component: UserPwd
      },
      // 文章分类
      {
        path: 'art-cate',
        name: 'artCate',
        component: ArtCate
      },
      // 文章列表
      {
        path: 'art-list',
        name: 'artList',
        component: ArtList
      },
    ]
  }
]

const router = new VueRouter({
  routes
})

export default router
